<?php

namespace backend\modules\member\controllers;


use backend\component\BackendBaseController;
use backend\service\UserService;
use common\models\info\Article;
use common\models\info\Comment;
use common\models\member\User;

class CommentController extends BackendBaseController
{
    public function actions()
    {
        return [
            "switch" => [
                "class" => "backend\actions\SwitchAction",
                "modelName" => Comment::className(),
                "field" => "status",
            ],
            "recommend" => [
                "class" => "backend\actions\SwitchAction",
                "modelName" => Comment::className(),
                "field" => "is_rec",
            ],
        ];
    }


    public function actionList() {
        if (\Yii::$app->request->getIsAjax()) {
            $data = UserService::commentListData(\Yii::$app->request->post());
            $data = UserService::commentDataAddArticle($data);
            return json_encode($data,true);
        }
        $model = new Comment();
        return $this->render("list",["model"=>$model]);
    }

    public function actionGet() {
        if (\Yii::$app->request->getIsAjax()) {
            $article_id = \Yii::$app->request->post('id');
            return json_encode(['res'=>Article::getFieldById($article_id,'title')],true);
        }
    }

}
